package reno.eureka.timecycle.entity;

public class VallisExplainMO {

    /**
     * 时间处理逻辑
     * <p>
     * id内时间为上次时间转换的时间戳
     * isWarm == true
     * 420-（当前时间戳-id时间戳）= 剩余时间
     * isWarm == false
     * 1200-（当前时间戳-id时间戳）= 剩余时间
     */
    public VallisExplainMO(CycleMO cycleMO) {
        long timeCurr = System.currentTimeMillis()/1000;
        long timeTarg = Long.valueOf(cycleMO.getId());
        long timeResult;
        if (cycleMO.isWarm()) {
            currval = "温暖";
            nextval = "寒冷";
            timeResult = 420 - (timeCurr - timeTarg);
        } else {
            currval = "寒冷";
            nextval = "温暖";
            timeResult = 1200 - (timeCurr - timeTarg) + 20;
        }
        if (timeResult < 0) {
            String temp = currval;
            currval = nextval;
            nextval = temp;
            if ("寒冷".equals(currval)) {
                timeResult = 1200 + timeResult;
            } else {
                timeResult = 420 + timeResult;
            }
        }
        long time = timeResult;
        int min = (int) ((time / 60) % 60);
        int sec = (int) (time % 60);
        if (min > 0) {
            timeString.append(" ").append(min).append(" 分钟");
        }
        if (sec > 0) {
            timeString.append(" ").append(sec).append(" 秒");
        }
    }

    private String currval;
    private String nextval;
    private StringBuilder timeString = new StringBuilder();

    public String getCurrval() {
        return currval;
    }

    public void setCurrval(String currval) {
        this.currval = currval;
    }

    public String getNextval() {
        return nextval;
    }

    public void setNextval(String nextval) {
        this.nextval = nextval;
    }

    public StringBuilder getTimeString() {
        return timeString;
    }

    public void setTimeString(StringBuilder timeString) {
        this.timeString = timeString;
    }

}
